package com.qingke.oms.command.user;

import com.qingke.oms.command.UserCommand;
import com.qingke.oms.pojo.Manufacturer;
import com.qingke.oms.pojo.User;
import com.qingke.oms.util.OMSConsole;

public class ApplyNewManufacturerCommand extends UserCommand {

	public ApplyNewManufacturerCommand(User user) {
		super(user);
	}

	@Override
	public void execute() {
		String code;
		String name;
		String address;
		String description;
		while(true){
			code=OMSConsole.promptNotEmpty("code:");
			if(dao.isManufacturerExistByCode(code)){
				OMSConsole.println("The code have been existed.");
				continue;
			}
			break;
		}
		name=OMSConsole.promptNotEmpty("name:");
		address=OMSConsole.promptNotEmpty("address:");
		description=OMSConsole.promptCanEmpty("description:");
		
		Manufacturer manufacturer=new Manufacturer();
		manufacturer.setCode(code);
		manufacturer.setName(name);
		manufacturer.setAddress(address);
		manufacturer.setDescription(description);
		
		boolean isSuccess=dao.insertManufacturer(manufacturer);
		if(isSuccess)
			OMSConsole.println("new a manufacturer success.");
		else
			OMSConsole.println("new a manufacturer failed.");
			
	}

}
